<template>

    <a-modal v-model:visible="LAYER.visible" :title="LAYER.title" :width="LAYER.width"
             :align-center="LAYER.alignCenter" :top="LAYER.top"
             :closable="LAYER.closable" :mask-closable="LAYER.maskClosable" :esc-to-close="LAYER.escToClose"
             :unmount-on-close="LAYER.unmountOnClose" :footer="LAYER.footer" :ok-text="LAYER.okText"
             :ok-loading="LAYER.okLoading" :cancel-text="LAYER.cancelText" :on-before-ok="onSubmit" @close="onCancel">

        <a-form ref="formRef" :model="formState" layout="vertical" :rules="RULES">


            <a-form-item label="会员电话" field="phoneNumber">
                <a-input v-model="formState.phoneNumber" allow-clear placeholder="请填写会员电话" :disabled="isUpdate"/>
            </a-form-item>


            <a-form-item label="真实姓名" field="readyName">
                <a-input v-model="formState.readyName" allow-clear placeholder="请填写真实姓名"/>
            </a-form-item>


            <a-form-item label="企业名称" field="companyName">
                <a-input v-model="formState.companyName" allow-clear placeholder="请填写企业名称"/>
            </a-form-item>


          <a-form-item label="是否有猪" field="isPig">
            <smart-bool v-model="formState.isPig" text-true="是" text-false="否"/>
          </a-form-item>


          <a-form-item v-if="formState.isPig" label="猪猪数量" field="pig">
            <a-input-number v-model="formState.pig" mode="button" min="0" placeholder="请填写猪猪数量"/>
          </a-form-item>


          <a-form-item v-if="formState.isPig" label="猪猪商品" field="pigGoodsCode">
            <smart-dict v-model="formState.pigGoodsCode" :url="ProductOptions.PigGoodsOptions" placeholder="请填写猪猪商品"/>
          </a-form-item>


        </a-form>

        <!--表单结束-->
    </a-modal>

</template>
<script lang="ts" setup>

import {EditModal} from "@/libs/core";
import {FIRM_EDIT} from '../resource/form'
import {SystemHttp} from '../resource/http'
import {ProductOptions} from "@/libs/options";

const props = defineProps({record: {type: Object, required: true}})
const emit = defineEmits(['cancel'])


const {BODY, RULES} = FIRM_EDIT
const config = {tplRecord: BODY, rawRecord: props.record, rowKey: 'id', emit}
// 将备注委托到封装类的执行方法上
const service = new EditModal(config).setAddRequest(SystemHttp.addMain).setUpdateRequest(SystemHttp.updateMain);

const {formRef, formState, LAYER, onCancel, onSubmit, isUpdate} = service
const title = service.isUpdate ? `修改企业会员` : '添加企业会员'
service.setMD(title, 500)

if (isUpdate) {
    formState.value.readyName = props.record.firmAttr.readyName
    formState.value.companyName = props.record.firmAttr.companyName
    formState.value.isPig = props.record.firmAttr.isPig
    formState.value.pig = props.record.firmAttr.pig
    formState.value.pigGoodsCode = props.record.firmAttr.pigGoodsCode


}
</script>

